/**
 * @author Rong
 * @brief 串口工具
 * @version 1.0.0
 * @date 2023-04-19
 * 
 * @copyright Copyright (c) 2023
 * 
 */
#ifndef __CGAME_SPU_H__
#define __CGAME_SPU_H__
#include <stddef.h>
#include "game_def.h"


class CGameSerial:public CGameObject{
protected:
  struct BaudTableItem_t {
    int baud;
    UINT32 flag;
  };


  typedef int fd_t;

  fd_t _fd;
  UINT32 _baudrate;

  static BOOL getBaudrateFlag(UINT32 baudrate, UINT32 &cflags);
  static BOOL setTTYAttribs(fd_t fd, int speed, int parity);

public:
  CGameSerial();
  BOOL init(const char* dev, UINT32 baudrate);
  BOOL deinit();

  virtual UINT32 read(void *buf, size_t bufSize);
  virtual UINT32 write(const void* dat, size_t datSize);
  virtual BOOL setBaudrate(UINT32 baudrate);
  virtual UINT32 getBaudrate();
};


#endif
